<?php

include 'func.php';

$mcryptTools = new McryptTool();

$method = $_REQUEST['method'];
$req = $_REQUEST;

$api_url = $req['api_url'];
$type = $req['type'];
$method = $req['method'];

unset($req['type']);
unset($req['api_url']);
unset($req['url']);
unset($req['method']);

//$req = json_encode($req);
//$encodeData = $mcryptTools->encodeRequest($req);
//$encodeData = $req;

$url = 'http://pc.oomall.com/' . $api_url;

if ($method == "post") {
    $con = curl_init((string)$url);
    curl_setopt($con, CURLOPT_POST, 1);
    curl_setopt($con, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($con, CURLOPT_POST, 1);
    curl_setopt($con, CURLOPT_POSTFIELDS, $req);
} else {
    $url = $url . '?' . http_build_query($req);
    $con = curl_init((string)$url);
    curl_setopt($con, CURLOPT_HEADER, false);
    curl_setopt($con, CURLOPT_RETURNTRANSFER, true);
}

$result = curl_exec($con);//直接返回的数据

$ret = json_decode($result, true);//转json
if (!$ret) {
    //如果json没有正常解析，说明接口返回不对，直接显示出来方便调试
    print_r($result);
    exit;
}
//$retData = $mcryptTools->decodeResponse($ret);
$retData = $ret;

if ($type == 'json') {
    $json_string = json_encode($retData, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
    echo $json_string;
} else {
    print_r($retData);
    exit;
}





